package main

import "fmt"

func PrintcityMap(cityMap map[string]string) {
	cityMap["China"] = "Beiijing"
	fmt.Println("cityMap = ", cityMap)
}

func main() {
	var myMap1 map[string]string
	if myMap1 == nil {
		fmt.Println("myMap1 is nil")
	}

	// 空map需要make后才能赋值
	myMap1 = make(map[string]string, 1)
	myMap1["one"] = "golang"
	myMap1["two"] = "C++"
	fmt.Println("myMap1 = ", myMap1)

	myMap2 := make(map[int]string)
	myMap2[1] = "C++"
	myMap2[2] = "Java"
	fmt.Println("myMap2 = ", myMap2)

	myMap3 := map[int]string{
		1: "Python",
		2: "C++",
	}
	fmt.Println("myMap3 = ", myMap3)

	fmt.Println("============")

	cityMap := make(map[string]string)
	// 添加元素
	cityMap["China"] = "Beijing"
	cityMap["Japan"] = "Tokyo"
	cityMap["USA"] = "NewYork"

	// 遍历
	for key, value := range cityMap {
		fmt.Println("key = ", key)
		fmt.Println("value = ", value)
	}

	fmt.Println("============")

	// 修改
	cityMap["USA"] = "DC"
	for key, value := range cityMap {
		fmt.Println("key = ", key)
		fmt.Println("value = ", value)
	}

	fmt.Println("============")

	// 删除
	delete(cityMap, "China")
	for key, value := range cityMap {
		fmt.Println("key = ", key)
		fmt.Println("value = ", value)
	}

	fmt.Println("============")

	// map传参，是引用传参
	fmt.Println("cityMap = ", cityMap)
	PrintcityMap(cityMap)
}
